<template>
  <div>
    <van-picker
      title="标题"
      show-toolbar
      :default-index="value"
      :columns="columns"
      @confirm="onConfirm"
      @cancel="$emit('close')"
    />
  </div>
</template>

<script>
import { Toast } from 'vant'
import { PatchUserProfile } from '@/api/user.js'
export default {
  data () {
    return {
      columns: ['男', '女']
    }
  },
  props: {
    value: {
      type: Number,
      required: true
    }
  },
  created () {

  },

  methods: {
    async onConfirm (val, index) {
      Toast.loading({
        duration: 0,
        message: '加载中...',
        forbidClick: true
      })
      try {
        await PatchUserProfile({
          gender: index
        })
        Toast.success('更新成功！')
        this.$emit('input', index)
        this.$emit('close')
      } catch (err) {
        Toast.fail('更新失败！')
      }
    }
  }
}
</script>

<style scoped lang='less'>

</style>
